﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LuaInterface;
using System.IO;

namespace RPGLUA
{
    class Room
    {
        private Lua scriptPower;
        private string scriptName;
        private string name;
        public Room(string name, Lua lua)
        {
            this.name = name;
            scriptName = name + ".lua";
            scriptPower = lua;
            scriptPower.DoFile(Directory.GetCurrentDirectory() + "\\" + scriptName);            
        }
        public string Name
        {
            get
            {
                return (string)scriptPower[name + ".name"];
            }
        }

        public string Description
        {
            get
            {
                return (string)scriptPower[name + ".description"];
            }
        }

        List<NPC> npcList = new List<NPC>();
        List<PassageWay> wayList = new List<PassageWay>();
        public void AddPassageWay(PassageWay pw)
        {
            wayList.Add(pw);
        }

        public void DescribeOccupants()
        {
            foreach (PassageWay pw in wayList)
            {
                Console.WriteLine(pw.description);
            }

            foreach (NPC n in npcList)
            {
                Console.WriteLine("There is a " + n.Name + " here.");
            }
        }

        public void AddNPC(NPC npc)
        {
            npcList.Add(npc);
        }

        public void DisplayInteractions()
        {
            foreach (NPC n in npcList)
            {
                Console.WriteLine("Press " + n.interactKey +
                 " to interact with " + n.Name);
            }

            foreach (PassageWay pw in wayList)
            {
                Console.WriteLine("Press " + pw.key + " to use the "
                 + pw.description);
            }
        }

        public void CheckInteractions(ref Room currentRoom, string keypress)
        {
            foreach (NPC n in npcList)
            {
                if (n.interactKey == keypress)
                {
                    n.Interact();
                    return;
                }
            }

            foreach (PassageWay pw in wayList)
            {
                if (pw.key == keypress)
                {
                    currentRoom = pw.destination;
                    scriptPower.DoString(currentRoom.name + ":OnEnter()");
                }
            }


        }

    }
}
